<?php

use \app\assets\BackendAsset as Asset;
use \app\models\tableModel\AdminRoleModel;

/* @var $this yii\web\View */

?>
<el-container class="wp-form-container">
    <el-header class="top-wrapper no-pb no-border bg-white no-box-shadow" height="auto" ref="mainScrollShadow">
        <el-row :inline="true" class="button-container">
            <el-col :xs="12" :sm="12" :md="12" :lg="5">
                <el-breadcrumb separator="/">
                    <el-breadcrumb-item>
                        <a @click="goToIndex"><i class="el-icon-location-outline"></i>&nbsp;首页</a>
                    </el-breadcrumb-item>
                    <el-breadcrumb-item @dblclick.native="window.open(window.location.href)">
                        &nbsp;站点设置(普通模式)
                    </el-breadcrumb-item>
                </el-breadcrumb>
            </el-col>
            <el-col :xs="12" :sm="12" :md="12" :lg="19" class="text-right">
                <?php if (AdminRoleModel::checkAuth('list')) { ?>
                    <el-button class="" size="mini" type="primary" icon="el-icon-edit"
                               @click.native="goToList()">
                        专业模式
                    </el-button>
                <?php } ?>
            </el-col>
        </el-row>
    </el-header>
    <el-main class="content-wrapper transits bg-white" v-if="listOver">

        <el-form :model="form" :rules="formRules" ref="ruleForm" label-width="240px"
                 class="form-400" label-position="right" v-if="listOver">
            <el-tabs v-model="activeGroup">
                <el-tab-pane v-for="(item, key) in dataList" :label="item.key"
                             :name="item.value" :key="key">
                    <el-scrollbar class="index-scroller" :ref="'scroll_' + item.value">

                        <div :key="sKey" :class="getFormItemContainerClass(sItem.type, sItem)"
                              v-for="(sItem, sKey, sIndex) in item['settings']">

                            <div v-if="sItem.top_line==setting.top_line_list.yes.value">
                                <div class="pt-2 pb-5 bg-gray mb-20" v-if="sIndex > 0"></div>
                                <h3 class="setting-top-title">
                                    <span class="is-title"></span>
                                    {{sItem.top_title}}
                                </h3>
                            </div>

                            <el-form-item :label="sItem.title" :prop="sItem.key"
                                          :error="customErrMsg[sItem.key]" class="form-item"
                                          :class="getFormItemClass(sItem.type)"
                                          :ref="'formItem_' + sItem.key"
                                          :inline-message="formInlineMsg(sItem.type)">

                                <template slot="label">
                                    <el-tooltip class="item display-inline" effect="light"
                                                placement="top-start" popper-class="z-index-top"
                                                :content="sItem.key">
                                        <div class="">
                                            <span v-text="sItem.title"
                                                  class="pointer"></span>
                                        </div>
                                    </el-tooltip>
                                </template>

                                <el-input size="small" :placeholder="'请输入' + sItem.title"
                                          v-if="sItem.type == setting.type_list.input.value"
                                          v-model="form[sItem.key]" class="form-element"
                                          :style="getItemStyle(sItem)">
                                    <template slot="append" v-if="sItem.unit">
                                        <span v-text="sItem.unit"></span>
                                    </template>
                                </el-input>

                                <el-input type="textarea" :placeholder="'请输入' + sItem.title"
                                          v-if="sItem.type == setting.type_list.textarea.value"
                                          :maxlength="sItem.length == 0 ? null : sItem.length"
                                          class="form-element" :autosize="{ minRows: 6}"
                                          v-model="form[sItem.key]" show-word-limit size="small"
                                          :style="getItemStyle(sItem)">
                                </el-input>

                                <el-radio-group v-model="form[sItem.key]" class="form-element"
                                                v-if="sItem.type == setting.type_list.radio.value"
                                                size="mini" :style="getItemStyle(sItem)">
                                    <el-radio v-for="(vItem, vKey) in sItem.option"
                                              :label="vItem.value">
                                        {{vItem.text}}
                                    </el-radio>
                                </el-radio-group>

                                <el-checkbox-group v-if="sItem.type==setting.type_list.check.value"
                                                   size="mini" class="form-element el-form-item-full"
                                                   v-model="form[sItem.key]" :style="getItemStyle(sItem)">
                                    <el-checkbox v-for="(vItem, vKey) in sItem.option"
                                                 :label="vItem.value">
                                        {{vItem.text}}
                                    </el-checkbox>
                                </el-checkbox-group>

                                <el-select v-model="form[sItem.key]" placeholder="请选择" size="small"
                                           v-if="sItem.type == setting.type_list.select.value"
                                           size="medium" class="form-item" :style="getItemStyle(sItem)">
                                    <el-option v-for="vItem in sItem.option" :key="vItem.value"
                                               :label="vItem.text" :value="vItem.value">
                                    </el-option>
                                </el-select>

                                <el-row v-if="sItem.type == setting.type_list.json.value"
                                        v-for="(vItem, vKey) in form[sItem.key]"
                                        class="input-group" :style="getItemStyle(sItem)">
                                    <el-col v-for="(oItem, oKey) in sItem.option" :key="oKey"
                                            :span="getJsonSpan(sItem, oKey)">
                                        <div class="display-inline json-input w-100">
                                            <el-input placeholder="请输入值" class="form-element"
                                                      v-model="vItem[oItem.key]" size="small">
                                                <template slot="prepend">
                                                    {{oItem.text}}
                                                </template>
                                            </el-input>
                                        </div>
                                    </el-col>
                                    <el-col v-if="sItem.can_add_row==setting.can_add_row_list.yes.value"
                                            :span="3" class="button-append">
                                        <el-button-group>
                                            <el-button @click="addRowValue(sItem.key, sItem.option)"
                                                       v-if="vKey + 1 == form[sItem.key].length"
                                                       type="success">
                                                添加
                                            </el-button>
                                            <el-button @click="delRowValue(vKey, sItem.key)" type="danger">
                                                删除
                                            </el-button>
                                        </el-button-group>
                                    </el-col>
                                </el-row>

                                <div v-if="sItem.type == setting.type_list.html.value" :id="'content_' + sItem.key"
                                     class="content-dom" :style="getItemStyle(sItem)">
                                    <?= $this->render('../common/html-editor.php', [
                                        'scenario' => 'settingImage',
                                        'code' => 'form[sItem.key]',
                                        'suffix' => 'sItem.key',
                                        'height' => 500
                                    ]);
                                    ?>
                                </div>

                                <div v-if="sItem.type == setting.type_list.image.value">
                                    <?= $this->render('../common/uploader.php', [
                                        'column' => 'form[sItem.key]',
                                        'variable' => [
                                            'sItem' => '{}',
                                            'sItem.key' => 'sItem.key'
                                        ],
                                        'scenario' => 'settingImage'
                                    ]) ?>
                                </div>

                                <div v-if="sItem.type == setting.type_list.excel.value">
                                    <?= $this->render('../common/uploader.php', [
                                        'column' => 'form[sItem.key]',
                                        'variable' => [
                                            'sItem' => '{}',
                                            'sItem.key' => 'sItem.key'
                                        ],
                                        'scenario' => 'settingExcel',
                                        'fileTypes' => [
                                            'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
                                            'application/vnd.ms-excel'
                                        ]
                                    ]) ?>
                                </div>

                                <div class="form-element-append display-block lh-normal"
                                     v-if="sItem.description">
                                    <div v-html="formatDesc(sItem.description)"
                                         class="font-fourth font-size-13"></div>
                                </div>

                            </el-form-item>

                        </div>

                        <el-empty v-if="!item['settings'] || $w.isEmpty(item['settings'])"
                                  description="暂无设置项"></el-empty>

                        <div class="form-bottom-free" v-else></div>

                    </el-scrollbar>
                </el-tab-pane>
            </el-tabs>

        </el-form>
    </el-main>
    <el-footer class="bottom-button" :height="50">
        <?php if (AdminRoleModel::checkAuth('update-plan')) { ?>
            <el-button size="mini" type="danger" @click="getList">重置</el-button>
        <?php } ?>
        <?php if (AdminRoleModel::checkAuth('update-plan')) { ?>
            <el-button size="mini" type="primary" @click="submitSave">
                保存
            </el-button>
        <?php } ?>
    </el-footer>
</el-container>

<?php
Asset::addCss($this, '/css/backend/setting-index.css');

Asset::addScript($this, '/js/backend/setting-index.js');
$this->registerJs('instance = new app();');
?>
